<template>
	<el-form :model="form" label-width="120px">
		<el-form-item label="标题">
			<el-input v-model="form.title" />
		</el-form-item>
		<el-form-item label="姓名">
			<el-input v-model="form.name" />
		</el-form-item>
		<el-form-item label="年龄">
			<el-input v-model="form.age" />
		</el-form-item>
		<el-form-item label="地址">
			<el-input v-model="form.address" />
		</el-form-item>
		<el-form-item label="性别">
			<el-input v-model="form.sex" />
		</el-form-item>
		<el-form-item label="邮箱">
			<el-input v-model="form.email" />
		</el-form-item>
		<el-form-item label="电话">
			<el-input v-model="form.tel" />
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="onSubmit">提交</el-button>
			<el-button>重置</el-button>
		</el-form-item>
	</el-form>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
// do not use same name with ref
const form = reactive({
	"title": '',
	"name": '',
	"age": 1,
	"address": '',
	"sex": "男",
	"email": '',
	"tel": '',
})

const onSubmit = async () => {
	const resp = await axios.post('/api/list', form)
	const { code, message } = resp.data
	ElMessage({ type: 'success', message })
}
</script>